// electron/repository/LoggerRepository.ts
import log from 'electron-log/main';
import path from 'path';
import { app } from 'electron';
import FileUtils from '../utils/FileUtils';

// 初始化 log
log.initialize();
log.transports.console.level = 'debug';
log.transports.file.level = 'info';
log.transports.file.resolvePathFn = (variables, message) => {
  return FileUtils.getDailyLogFile('client');
};

log.info('日志系统初始化完成  ' + FileUtils.getDailyLogFile('client'));

type LogLevel = 'error' | 'warn' | 'info' | 'verbose' | 'debug' | 'silly';

class LoggerRepository {
  write(level: LogLevel, ...args: any[]) {
    log[level](...args);
  }

  warnInvalid(level: string, ...args: any[]) {
    log.warn(`无效的日志级别 "${level}"，消息:`, ...args);
    log.debug(...args);
  }

  logError(error: any) {
    log.error('处理日志消息时出错:', error);
  }

  info(message: string) {
    log.info(message);
  }
}

export const loggerRepository = new LoggerRepository();
